﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace PizzaService.View
{
    /// <summary>
    /// Interaction logic for CreateNewFood.xaml
    /// </summary>
    public partial class CreateNewFoodWindow : Window
    {
        public CreateNewFoodWindow()
        {
            InitializeComponent();
            this.Loaded += CreateNewFoodWindow_Loaded;
        }

        void CreateNewFoodWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = App.Controller.NewFoodModel;
        }

        /// <summary>
        /// Cancel Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// OK Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (ComboType.SelectedItem != null && !String.IsNullOrEmpty(App.Controller.NewFoodModel.Food.Name)
                && !Decimal.Equals(App.Controller.NewFoodModel.Food.Preis_klein, 0.0) && !Decimal.Equals(App.Controller.NewFoodModel.Food.Preis_groß, 0.0))
            {
                if (App.Controller.CreateNewPizza(ComboType.SelectedItem.ToString()))
                    this.Close();
            }
            else
                MessageBox.Show("Überprüfen sie Ihre Eingaben, alle Felder müssen ausgefüllt werden.");
        }

        /// <summary>
        /// Zutat hinzufügen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddZutat_Click_1(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource is Button)
            {
                var btn = (e.OriginalSource as Button);

                // get ListViewItem from Button DataContext
                var item = btn.DataContext;

                // remove the item from the list

                App.Controller.AddZutat(item);
            }
        }
        /// <summary>
        /// Zutat nicht hinzufügen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RemoveZutat_Click_1(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource is Button)
            {
                var btn = (e.OriginalSource as Button);

                // get ListViewItem from Button DataContext
                var item = btn.DataContext;

                // remove the item from the list

                App.Controller.RemoveZutat(item);
            }
        }


    }
}
